﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using Vowei.Core.Models;

namespace Vowei.Workflows.Tickets
{

    public sealed class CancelTasks : CodeActivity
    {
        public InArgument<Task[]> AllReviewTasks { get; set; }

        public InArgument<List<Task>> AcceptedReviewTasks { get; set; }

        public InArgument<IVoweiContext> DatabaseContext { get; set; }

        protected override void Execute(CodeActivityContext context)
        {
            var art = AllReviewTasks.Get(context);
            var accepted = AcceptedReviewTasks.Get(context);
            var dbcontext = DatabaseContext.Get(context);
            var canceled = art.Except(accepted);

            foreach (var task in canceled)
                dbcontext.TicketStatusManager.Cancel(task);

            dbcontext.SaveChanges();
        }
    }
}
